package com.fjd.controller;

import com.fjd.dto.OrderSubmitDTO;
import com.fjd.entity.ShoppingCart;
import com.fjd.result.Result;
import com.fjd.service.ShoppingCartService;
import com.fjd.vo.CartVO;
import com.fjd.vo.GoodVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopping/cart")
@Slf4j
@Api(tags = "购物车相关接口")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/list")
    @ApiOperation("获取购物车内商品数据")
    public Result<List<CartVO>> list(){
        List<CartVO> cartVOS = shoppingCartService.list();
        return Result.success(cartVOS);
    }

    @PostMapping("/add")
    @ApiOperation("在购物车内新增商品数据")
    public Result add(@RequestBody OrderSubmitDTO orderSubmitDTO){
        shoppingCartService.add(orderSubmitDTO);
        return Result.success();
    }

    @PostMapping("/remove")
    @ApiOperation("删除购物车内的商品")
    public Result remove(@RequestBody List<String> ids){
        shoppingCartService.remove(ids);
        return Result.success();
    }
}
